class lib.system.mlf.FlowProcessor
{
	private static var flowProcessor:FlowProcessor;
	private var systemLib:MovieClip;
	private var tick:Number;
	private var eventFlow:Array;

	private var flowName:String;
	
	public function FlowProcessor()
	{
		systemLib=_root.Lib.notes.system.mlf.GateKeeper;
		tick=0;
		eventFlow=new Array();
		flowName="";
	}

	public static function getInstance()
	{
		if (flowProcessor==null)
		{
			flowProcessor=new FlowProcessor();
		}
		return flowProcessor;
	}

	public function regRules(rulesName:String)	// and rulesObj <-rulesXML, now ignore rulesObj
	{
		/*if (flowName=="")
		{
			flowName=rulesName;
			return true;
		}
		else return false;*/
		// no reject now, alloc new flow [2007-12-24]
		flowName=rulesName;
		eventFlow=new Array();
		tick=0;
		return true;
	}
	
	public function regEvent(type:String, param:Object)
	{
		// trace("regEvent: "+type);
		var evtObj=new Object();
		evtObj.type=type;
		evtObj.param=param;
		eventFlow.push(evtObj);
	}

	public function launchEvent()
	{
		// trace("eventFlow.length: "+eventFlow.length);
		if (eventFlow[tick]!=null)
		{
			// trace(tick+".tick: "+eventFlow[tick].type);
			systemLib.dispatchMessage(eventFlow[tick++]);
			// trace("tick: "+tick);
			// tick++;
		}
		else 
		{
			// trace("FlowProcessor.noTick");
			systemLib.dispatchMessage({type:"noTick", param:flowName});
			flowName="";
			eventFlow=new Array();
			tick=0;
		}
	}

	public function accessCurrentEvent():Object
	{
		return eventFlow[tick-1];
	}
}